home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / go32 / stub.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-18  |  2.0 KB  |  89 lines

  1. /* This is file STUB.C */
  2. /*
  3. ** Copyright (C) 1993 DJ Delorie, 24 Kirsten Ave, Rochester NH 03867-2954
  4. **
  5. ** This file is distributed under the terms listed in the document
  6. ** "copying.dj", available from DJ Delorie at the address above.
  7. ** A copy of "copying.dj" should accompany this file; if not, a copy
  8. ** should be available from where this file was obtained.  This file
  9. ** may not be distributed without a verbatim copy of "copying.dj".
  10. **
  11. ** This file is distributed WITHOUT ANY WARRANTY; without even the implied
  12. ** warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. */
  14.  
  15. #include <stdio.h>
  16. #include <process.h>
  17. #include <dos.h>
  18. #include <io.h>
  19. #include <string.h>
  20.  
  21. #include "gotypes.h"
  22. #include "stubinfo.h"
  23.  
  24. StubInfo stub_info = {
  25.   STUB_INFO_MAGIC,
  26.   sizeof(StubInfo),
  27.   "go32",
  28.   {
  29.     GO32_RELEASE_NUMBER,
  30.     GO32_RELEASE_TYPE_C,
  31.     GO32_MINOR_VERSION,
  32.     GO32_MAJOR_VERSION
  33.   },
  34.   262144L,
  35.   0,
  36.   "",
  37.   1,
  38.   0L
  39. };
  40.  
  41. unsigned _heaplen = 8192;
  42. unsigned _stklen = 4096;
  43.  
  44. char hex[] = "0123456789abcdef";
  45.  
  46. void x2s(int v, char *s)
  47. {
  48.   int i;
  49.   for (i=0; i<4; i++)
  50.   {
  51.     s[3-i] = hex[v&15];
  52.     v >>= 4;
  53.   }
  54.   s[4] = 0;
  55. }
  56.  
  57. char emsg[] = "Cannot exec ";
  58. char emsg2[] = "\r\n";
  59.  
  60. main(int argc, char **argv)
  61. {
  62.   char newpsp[128+16];
  63.   char s_argc[5], s_seg[5], s_argv[5];
  64.   char s_info_seg[5], s_info_ofs[5];
  65.   char s_psp[5];
  66.   int r, oldpsp=_psp;
  67.  
  68.   x2s(argc, s_argc);
  69.   x2s(_DS, s_seg);
  70.   x2s((int)argv, s_argv);
  71.   x2s(_DS, s_info_seg);
  72.   x2s((int)(&stub_info), s_info_ofs);
  73.   x2s(oldpsp, s_psp);
  74.  
  75.   /* fake out PSP or spawn will override arguments (uck) */
  76.   _psp = FP_SEG(newpsp) + ((FP_OFF(newpsp)+15-128)>>4);
  77.   /* must wait, as go32 reads argv/argc from our memory space */
  78.   r = spawnlp(P_WAIT, stub_info.go32, stub_info.go32, "!proxy", s_argc, s_seg, s_argv, s_info_seg, s_info_ofs, s_psp, 0);
  79.   _psp = oldpsp;
  80.  
  81.   if (r == -1)
  82.   {
  83.     write(2, emsg, sizeof(emsg)-1);
  84.     write(2, stub_info.go32, strlen(stub_info.go32));
  85.     write(2, emsg2, sizeof(emsg2)-1);
  86.   }
  87.   return r;
  88. }
  89.